package com.gohome.gohomechat.presenter;

import com.gohome.gohomechat.model.RegisterModel;
import com.gohome.gohomechat.model.modellistener.RegisterModelInterface;
import com.gohome.gohomechat.presenter.callback.RegisterCallBack;
import com.gohome.gohomechat.presenter.presenterlistener.RegisterPresenterInterface;
import com.gohome.gohomechat.ui.viewlistener.RegisterViewInterface;

/**
 * Created by dllo on 16/2/29.
 */
public class RegisterPresenter extends BasePresenter<RegisterViewInterface> implements RegisterPresenterInterface {
    private RegisterViewInterface registerViewInterface;
    private RegisterModelInterface registerModelInterface;

    public RegisterPresenter(RegisterViewInterface registerViewInterface) {
        this.registerViewInterface = registerViewInterface;
        this.registerModelInterface = new RegisterModel();
    }

    @Override
    public void register() {
        registerViewInterface.showDialog();
        registerModelInterface.register(registerViewInterface.userName(),
                registerViewInterface.userPsw(), registerViewInterface.againUserPsw(),
                new RegisterCallBack() {
                    @Override
                    public void registerSuccess() {
                        registerViewInterface.dismissDialog();
                        registerViewInterface.toRegisterSuccess();
                    }

                    @Override
                    public void registerFailed_network() {
                        registerViewInterface.dismissDialog();
                        registerViewInterface.toRegisterFailed_network();
                    }

                    @Override
                    public void registerFailed_repeat() {
                        registerViewInterface.dismissDialog();
                        registerViewInterface.toRegisterFailed_repeat();
                    }

                    @Override
                    public void registerFailed_withoutPermission() {
                        registerViewInterface.dismissDialog();
                        registerViewInterface.toRegisterFailed_withoutPermission();
                    }

                    @Override
                    public void registerFailed_other(String message) {
                        registerViewInterface.dismissDialog();
                        registerViewInterface.toRegisterFailed_other(message);
                    }
                });
    }
}
